package com.hadoop.flowsum;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by yu756 on 2020/1/18 13:36
 */
public class FlowCountReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

    FlowBean v = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        long sun_upFlow = 0;
        long sum_downFlow = 0;
        for (FlowBean flowBean : values) {
            sun_upFlow += flowBean.getUpFlow();
            sum_downFlow += flowBean.getDownFlow();
        }

        v.set(sun_upFlow, sum_downFlow);

        context.write(key, v);


    }
}
